﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Course.Entity;

public partial class sysadmin_CourseManager_AddCourseResourceType : PowerCreator.LMS.Web.Base.BasePage
{
    Course opCourse = new Course();

    protected void Page_Load(object sender, EventArgs e)
    {
        ViewState["TypeID"] = "0";
        if (Request.QueryString["tid"] != null)
        {
            ViewState["TypeID"] = Request.QueryString["tid"].ToString();
        }
        if (!IsPostBack)
        {
            InitPage();
            BinderPage();
        }
    }
    protected override void InitPage()
    {
        lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddCourseResourceType_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_CourseResourceType.Text = GetLanageValueByKey("lbl_AddCourseResourceType_CourseResourceType", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Save.Text = GetLanageValueByKey("btn_AddCourseResourceType_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Reset.Text = GetLanageValueByKey("btn_AddCourseResourceType_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private void BinderPage()
    {
        VOTResourceType vo = new VOTResourceType();
        if (ViewState["TypeID"].ToString() != "0")
        {
            vo = opCourse.LoadResourceType(int.Parse(ViewState["TypeID"].ToString()));
            txt_CourseResourceType.Value = vo.RestpName;
        }

    }
    protected void btn_Back_Click(object sender, EventArgs e)
    {
        string url = "CourseResourceType.aspx";
        Script.RedirectURL(url);
    }
    private bool CheckPageData()
    {
        string search = string.Format("RestpName='{0}'", txt_CourseResourceType.Value);
        if (ViewState["TypeID"].ToString() != "0")
        {
            search = search + " and RestpID<>" + ViewState["TypeID"].ToString();
        }
        if (opCourse.QueryResourceTypeCount(search) != 0)
        {
            lbl_addcourseresourcetype_msg_courseresourcetypename.Text = GetLanageValueByKey("AddResourceInfo_msg_m9", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        bool flag = false;
        if (!CheckPageData()) return;

        VOTResourceType vo = new VOTResourceType();
        if (ViewState["TypeID"].ToString() != "0")
        {
            vo = opCourse.LoadResourceType(int.Parse(ViewState["TypeID"].ToString()));
        }
        vo.RestpName = txt_CourseResourceType.Value;
        if (ViewState["TypeID"].ToString() != "0")
        {
            vo.RestpID = int.Parse(ViewState["TypeID"].ToString());
            flag = opCourse.UpdateResourceType(vo);
        }
        else
        {
            vo.RestpFatherID = 0;
            flag = opCourse.AddResourceType(vo);
        }
        if (flag)
        {
            string url = "CourseResourceType.aspx";
            Script.RedirectURL(url);
        }
    }
}
